<?php

namespace App\Http\Middleware;

use App\Http\Services\LoginService;
use App\Http\Services\SchoolService;
use Closure;

class MobileLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     *
     *
     *
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = LoginService::getUser();
        if(empty($user)){
            return redirect('/mobile/login');
        }
        $user['school'] = SchoolService::getSchoolInfo($user['ocode']);
        $user['id'] = $user['stu_id'];
        $request->merge(['user' => $user]);
        return $next($request);
    }
}
